#create the UT corplate for the nest_map.py
from nest_map import map_key,map_value, get_sentence
import unittest

class TestNestMap(unittest.TestCase):
  nest_map = {2:{3:'name', 2:'friend', 1:'teacher'}, 4: {2:'My', 1:'Your', 3:'Their'}, 3:{1:'am', 3:'is', 2:'are'}, 1:{2:'Bob', 3:'Jack', 1:'Lucy'}}
  #create test case for function named map_key
  # input keyvalue: {4:to}
  # input nest map:  {2:{3:name, 2:friend, 1:teacher}, 4: {2:My, 1:Your, 3:Their}, 3:{1:am, 3:is, 2:are}, 1:{2:Bob, 3:Jack, 1:Lucy}}
  # output: {2:My, 1:Your, 3:Their}
  def test_map_key(self):
    keyvalue = {4: 'to'}    
    self.assertEqual(map_key(keyvalue, self.nest_map), {2:'My', 1:'Your', 3:'Their'})

  # input keyvalue: {2:"I"}
  # output: {3:'name', 2:'friend', 1:'teacher'}
  def test_map_key_2(self):
    keyvalue = {2: 'I'}
    self.assertEqual(map_key(keyvalue, self.nest_map), {3:'name', 2:'friend', 1:'teacher'})

  # input keyvalue: {3:"for"}
  # output: {1:'am', 3:'is', 2:'are'}
  def test_map_key_3(self):
    keyvalue = {3: 'for'}
    self.assertEqual(map_key(keyvalue, self.nest_map), {1:'am', 3:'is', 2:'are'})
  
  #create test cases for map_value, which is not implemented yet
  # input 1 is keyvalue
  # another input is output of map_key
  # the map_value will get the value from the input keyvalue
  # then get the letter count of the value
  # then use the letter count as key to get the value from the map_key
  # input: keyvalue: {4:to}
  # input: {2:My, 1:Your, 3:Their}
  # output: "My"
  def test_map_value(self):
    keyvalue = {4: 'to'}
    self.assertEqual(map_value(keyvalue, {2:'My', 1:'Your', 3:'Their'}), "My")
  
  # input: keyvalue: {2:"I"}
  # input: {3:'name', 2:'friend', 1:'teacher'}
  # output: "teacher"
  def test_map_value_2(self):
    keyvalue = {2: 'I'}
    self.assertEqual(map_value(keyvalue, {3:'name', 2:'friend', 1:'teacher'}), "teacher")

  # input: keyvalue: {3:"for"}
  # input: {1:'am', 3:'is', 2:'are'}
  # output: "is"
  def test_map_value_3(self):
    keyvalue = {3: 'for'}
    self.assertEqual(map_value(keyvalue, {1:'am', 3:'is', 2:'are'}), "is")

  # input: keyvalue: {1:"you"}
  # input: {2:'Bob', 3:'Jack', 1:'Lucy'}
  # output: "Jack"
  def test_map_value_4(self):
    keyvalue = {1: 'you'}
    self.assertEqual(map_value(keyvalue, {2:'Bob', 3:'Jack', 1:'Lucy'}), "Jack")

  # create test cases for func：get_sentence
  # input 1 is map
  # input 2 is nest_map
  # the func will interate the input map to get the keyvalues
  # then call map_key with keyvalue and nest_map, to get the map_key_result
  # then call map_value with keyvalue and map_key_result, to get the map_value_result
  # then append the map_value_result to be a sentence
  # input: [{4:"to"}, {2:"I"}, {3:"for"}, {1:"and"}]
  # input: {2:{3:name, 2:friend, 1:teacher}, 4: {2:My, 1:Your, 3:Their}, 3:{1:am, 3:is, 2:are}, 1:{2:Bob, 3:Jack, 1:Lucy}}
  # output: "My teacher is Jack"
  def test_get_sentence(self):
    map =  [{4:"to"}, {2:"I"}, {3:"for"}, {1:"and"}]
    self.assertEqual(get_sentence(map, self.nest_map), "My teacher is Jack")
  
  # input: [{4:"to"}, {2:"I"}, {3:"for"}, {1:"and"}]
  # input: {2:{3:name, 2:friend, 1:is}, 4: {2:Today, 1:Your, 3:Their}, 3:{1:am, 3:not, 2:are}, 1:{2:Bob, 3:sunny, 1:Lucy}}
  # output: "Today is not sunny"
  def test_get_sentence_2(self):
    map =  [{4:"to"}, {2:"I"}, {3:"for"}, {1:"and"}]
    nest_map = {2:{3:'name', 2:'friend', 1:'is'}, 4: {2:'Today', 1:'Your', 3:'Their'}, 3:{1:'am', 3:'not', 2:'are'}, 1:{2:'Bob', 3:'sunny', 1:'Lucy'}}
    self.assertEqual(get_sentence(map, nest_map), "Today is not sunny")
  
if __name__ == '__main__':
  unittest.main()
